import { createRouter, createWebHashHistory } from "vue-router";
import baseRoutes from "./routes";

const Base = () => import(/* webpackChunkName: "Base" */ "@/layouts/base/base.vue");
const Login = () => import(/* webpackChunkName: "Login" */ "@/layouts/login/login.vue");
const Logout = () => import(/* webpackChunkName: "Logout" */ "@/layouts/logout/logout.vue");
const NotFound = () => import(/* webpackChunkName: "NotFound" */ "@/layouts/404/404.vue");

const routes = [
  {
    path: "/",
    name: "Root",
    redirect: "/base",
    meta: {
      title: "",
      isKeepAlive: false,
    },
  },
  {
    path: "/base",
    name: "Base",
    component: Base,
    redirect: "/dashboard",
    children: [...baseRoutes],
    meta: {
      title: "主页面",
      isKeepAlive: false,
    },
  },

  {
    path: "/login",
    name: "Login",
    component: Login,
    meta: {
      title: "登录页面",
      isKeepAlive: false,
    },
  },

  {
    path: "/logout",
    name: "Logout",
    component: Logout,
    meta: {
      title: "退出页面",
      isKeepAlive: false,
    },
  },

  {
    path: "/404",
    name: "404",
    component: NotFound,
    meta: {
      title: "404页面",
      isKeepAlive: false,
    },
  },

  {
    // vue2 匹配剩余路径用 "*", vue3 用 "/:pathMatch(.*)",
    path: "/:pathMatch(.*)",
    name: "404",
    component: NotFound,
    meta: {
      title: "404页面",
      isKeepAlive: false,
    },
  },
];

const router = createRouter({
  history: createWebHashHistory(),
  // 加载所有路由
  routes,
});

export default router;
